(function ($) {
    $.fn.bindTable = function (options) {
        var defaults = {
            jsonData: {},  //传入的jsondata.list数据
            page: 1,
            pageSize: 0,
            table: null,
            handle: function (index, e) {
            } //用来处理一些变色的操作等。/index:当前tr的索引。 e:当前tr的元素

        };
        var opts = $.extend(defaults, options);
        $table = opts.table;
        var data = opts.jsonData.data.list;//$.parseJSON(opts.jsonData);
        var trhtml = "";
        var val;
        if (data == null || data == undefined || data.length == 0) {
            trhtml = "<tr><td colspan='" + $table.find("thead tr th").length + "' align='center' style='text-align: center;'>暂无数据</td></tr>";
            $table.find("tbody").html(trhtml);
        } else {
            for (var i = 0; i < data.length; i++) {
                eval("pk=data[i]." + ($table.attr("data-pk") || "id"));
                trhtml += "<tr id='" + (pk == undefined ? "" : pk) + "' class='" + (i % 2 ? "tr_bg" : "") + "'>";
                $table.find("thead tr th").each(function () {
                    if ($(this).attr("data-order") == "1") {
                        trhtml += "<td>" + ((opts.page - 1) * opts.pageSize + (i + 1) ) + "</td>";
                    } else {
                        eval("val=data[i]." + $(this).attr("name"));
                        if (val == undefined || val == null || $(this).attr("name") == undefined) {
                            val = "";
                        }
                        var align = $(this).attr("align") || "";
                        var hander = $(this).attr("data-handel") || false;
                        var param = $(this).attr("data-param") || false;
                        var style = $(this).attr("data-style") || "";
                        if (style != "") {
                            style = " style='" + style + "'";
                        }
                        var cls = $(this).attr("data-class") || "";
                        if (cls != "") {
                            cls = " class='" + cls + "'";
                        }
                        var dataType = $(this).attr("data-type") || "";
                        var housingType = $(this).attr("data-housingType") || "";
                        var radio = $(this).find("input[type=radio]").length > 0;
                        var chkbox = $(this).attr("data-chkbox") || false;
                        if (chkbox) {
                            trhtml += "<td  style='width: 68px;'>  <input type='checkbox' class='i-checks chkbox' value='" + pk + "' ></td>";
                        } else if (radio) {
                            $(this).find("input[type=radio]").addClass("hide");
                            $(this).addClass("chkradioall");
                            trhtml += "<td " + style + cls + ">  <input type='radio' name='radio_1' class='i-checks chkradio' value='" + pk + "' ></td>";
                        } else if (hander) {
                            var handerStr = $(this).find(".hidden").html();
                            if (handerStr != undefined && handerStr != "") {
                                for (var item in data[i]) {
                                    eval("var re = /{" + item + "}/g;");
                                    handerStr = handerStr.replace(re, data[i][item]);
                                }
                            } else if (param) {
                                eval("var handerStr =" + hander + "(param,val);");
                            } else {
                                eval("var handerStr =" + hander + "(data[i]);");
                            }
                            trhtml += "<td " + style + cls + ">" + handerStr + "</td>";
                        } else if (dataType != "") {
                            if (dataType == "datetime") {
                                trhtml += "<td " + style + cls + "  name= " + val + " >" + formatDateTime(val) + "</td>";
                            }
                            else if (dataType == "date-m") {
                                trhtml += "<td " + style + cls + "  name= " + val + " >" + formatDateMonth(val) + "</td>";
                            }
                            else if (dataType == "img") {
                                trhtml += "<td " + style + cls + "  name= " + val + " ><img src='" + (val == "" || val == null || val == 'null' || val == undefined ? "/static/image/default.png" : val) + "'></td>";
                            }
                            else if (dataType == "date") {
                                trhtml += "<td  " + style + cls + " name= " + val + " >" + formatDate(val) + "</td>";
                            } else if (dataType == "datetime_") {
                                trhtml += "<td  " + style + cls + " name= " + val + " >" + formatDateTime_(val) + "</td>";
                            }
                        } else if (housingType != '') {
                            eval("type=" + housingType + "(data[i])");
                            trhtml += "<td " + style + cls + "  name= " + val + " >" + type + "</td>";
                        }
                        else {
                            trhtml += "<td  " + style + cls + " name= " + val + " >" + val + "</td>";
                        }
                    }
                });
                trhtml += "</tr>";
            }
            $table.find("tbody").html(trhtml);
            //全局选中
            $table.find('input[type="checkbox"]').iCheck({
                checkboxClass: 'icheckbox_flat-blue',
                radioClass: 'iradio_flat-blue'
            });

            $(".checkbox-toggle").click(function () {
                var clicks = $(this).data('clicks');
                if (clicks) {
                    $table.find('input[type="checkbox"]').iCheck("uncheck");
                } else {
                    $table.find('input[type="checkbox"]').iCheck("check");
                }
                $(this).data("clicks", !clicks);
            });
        }
    };

    //将json串绑定入该元素其下name属性控件
    $.fn.bindView = function (options) {
        var defaults = {
            jsonData: {},  //传入的jsondata.list数据
            handle: function () {
                //绑定完成执行的回调函数
            }
        };
        var opts = $.extend(defaults, options);
        $table = this;
        var data = opts.jsonData;
        $table.find("input[type=text],input[type=number],input[type=date],input[type=tel]").each(function () {
            var word = $(this).attr("name");
            var s;
            if (word) {
                eval("s=data." + word);
                if (s == null || s == undefined) {
                    s = "";
                }

                var dataType = $(this).attr("data-type") || "";
                if (dataType != "") {
                    if (dataType == "datetime") {
                        s = formatDateTime(s);
                    }
                    else if (dataType == "date-m") {
                        s = formatDateMonth(s);
                    }
                    else if (dataType == "date") {
                        s = formatDate(s);
                    } else if (dataType == "divided") {
                        s = (s == 0) ? 0 : s / 10000;
                    } else if (dataType == "year") {
                        s = (s == 0) ? 0 : s / 12;
                    } else if (dataType == "date-y") {
                        s = Comm.formatDateYear(s);
                    }
                }
                $(this).val(s);

            }
            $.fn.dataHander($(this).attr("data-handel"), s, this, data);
        });


        $table.find("input[type='radio']").each(function () {
            var word = $(this).attr("name");
            var type = $(this).attr("data-type") || '';
            eval("var s=data." + word);
            if (s == null || s == undefined) {
                s = "";
            }
            //Checked样式
            var $radioitem = $table.find("input:radio[name='" + word + "'][value='" + s + "']");
            if ($radioitem.next().hasClass("iCheck-helper")) {
                $radioitem.iCheck('check');
            } else {
                $radioitem.attr("checked", true);
            }
            if (type != '') {
                if ($(this).attr("value") == s) {
                    $("input[name='" + word + "']").parent().next(".cenginput").addClass("hide");
                    $(this).parent().next(".cenginput").removeClass("hide");
                }
            }
            $.fn.dataHander($(this).attr("data-hander"), s, this, data);
        });

        $table.find("select").each(function () {
            var word = $(this).attr("name");
            eval("var s=data." + $(this).attr("name"));
            if (s == null || s == undefined) {
                s = "";
            }
            $(this).val(s);
            $(this).attr("data-val", s);
            if ($(this).hasClass("chosen-select")) {
                $(this).trigger("chosen:updated");
            }
            $.fn.dataHander($(this).attr("data-hander"), s, this, data);
        });

        $table.find("textarea").each(function () {
            eval("var s=data." + $(this).attr("name"));
            if (s == null || s == undefined) {
                s = "";
            }
            $(this).val(s);
            $.fn.dataHander($(this).attr("data-hander"), s, this, data);
        });


        $table.find("input[type='checkbox']").each(function () {
            eval("var s=data." + $(this).attr("name"));
            if (s == null || s == undefined) {
                s = "";
            }
            if ((',' + s + ',').indexOf(',' + $(this).val() + ',') != -1) {
                $(this).attr("checked", true);
            }

        });

        $table.find("input[type='hidden']").each(function () {
            eval("var s=data." + $(this).attr("name"));
            if (s == null || s == undefined) {
                s = "";
            }
            $(this).val(s);
            var $imgsrc = $(this).attr("data-img-id");
            if ($imgsrc != "" && $imgsrc != undefined) {
                $("#" + $imgsrc).attr("src", ( s == "" || s == undefined || s == null || s == 'null' ? "/static/image/default.png" : s));
            }
            $.fn.dataHander($(this).attr("data-hander"), s, this, data);
        });

        opts.handle();
    };

    $.fn.dataHander = function (hander, val, obj, data) {
        if (hander != null && hander != undefined && hander != "")
            eval(hander + "(val,obj,data)");
    };

    $.fn.bindTemplate = function (options) {
        var defaults = {
            Template: null,
            jsonData: {},  //传入的jsondata.list数据
            page: 1,
            pageSize: 0,
            handle: function (index, e) {
            } //用来处理一些变色的操作等。/index:当前tr的索引。 e:当前tr的元素
        };
        var opts = $.extend(defaults, options);
        $table = this;
        var data = opts.jsonData.data.list;//$.parseJSON(opts.jsonData);
        var temphtml = "";
        if (data == null || data == undefined || data.length == 0) {
            temphtml = "<div>暂无数据</div>";
            $table.html(temphtml);
        } else if (opts.Template == null) {
            temphtml = "<div>模板错误</div>";
            $table.html(temphtml);
        } else {
            var templateHandleArr = [];
            var templateHandle = $(this).attr("data-template-handle");
            if (templateHandle) {
                templateHandle.indexOf(",") == -1 ? templateHandleArr.push(templateHandle) : templateHandleArr = templateHandle.split(",");
            }
            for (var i = 0; i < data.length; i++) {
                var handerStr = opts.Template;

                for (var j = 0; j < templateHandleArr.length; j++) {
                    var key = templateHandleArr[j].split("#")[0];
                    var func = templateHandleArr[j].split("#")[1];
                    eval("var re = /{" + key + "}/g;");
                    var val = data[i][key];
                    if (val == undefined || val == null) {
                        val = "";
                    }
                    switch (func) {
                        case "data":
                            handerStr = handerStr.replace(re, formatDate(val));
                            break;
                        case "dataTime":
                            handerStr = handerStr.replace(re, formatDateTime(val));
                            break;
                        case "dataTime_":
                            handerStr = handerStr.replace(re, formatDateTime_(val));
                            break;
                        case "dataHourMin":
                            handerStr = handerStr.replace(re, dataHourMin(val));
                            break;
                        default:
                            eval("var funVal =" + func + "(data[i])");
                            handerStr = handerStr.replace(re, funVal);
                    }
                }

                //替换后 元素失效
                for (var item in data[i]) {
                    eval("var re = /{" + item + "}/g;");
                    var val = data[i][item];
                    if (val == undefined || val == null) {
                        val = "";
                    }
                    handerStr = handerStr.replace(re, val);
                }
                temphtml += handerStr;
            }
        }
        $table.html(temphtml);
        $.each($table.find("[data-src]"), function (i, item) {
            var src = $(item).attr("data-src");
            $(item).attr("src", (src == "" || src == undefined || src == "" || src == 'null' ? "/static/image/default.png" : src))
        })
    };

    //返回改元素下name不为空的 url查询串
    $.fn.getParams = function () {
        $table = this;


        var jsonstr = "";
        $table.find("input[name!='']").each(function () {
            var v = $(this).val();
            if (v == undefined || v == "") {
                v = "";
            }
            if ($(this).attr("name") != null) {
                jsonstr += "" + $(this).attr("name") + "=" + v + "&";
            }
        });

        $table.find("select[name!='']").each(function () {
            var v = $(this).val();
            if (v == undefined || v == "") {
                v = "";
            }
            jsonstr += "" + $(this).attr("name") + "=" + v + "&";
        });
        jsonstr += "abc=1";
        jsonstr = jsonstr.replace("&abc=1", "");
        return jsonstr;
    };
    //返回该元素下name不为空的json串
    $.fn.getJson = function () {
        $table = this;
        var jsonstr = "{";
        $table.find("input[name!='']").each(function () {
            var v = $(this).val();
            if (v == undefined || v == "") {
                v = "''";
            }
            if ($(this).attr("name") != null) {
                jsonstr += "'" + $(this).attr("name") + "':'" + v + "',";
            }
        });
        $table.find("select[name!='']").each(function () {
            var v = $(this).val();
            if (v == undefined || v == "") {
                v = "''";
            }
            jsonstr += "'" + $(this).attr("name") + "':'" + v + "',";
        });
        jsonstr += "abc:1}";
        jsonstr = jsonstr.replace(",abc:1", "");
        return jsonstr;
    };
})(jQuery);

/*
 执行绑定操作
 */
var BindData = {
    //绑定编辑页面
    bindview: function (options) {
        var defaults = {
            formid: "form",
            placeholder: true,
            data: null,
            url: null,
            backFun: null,
            callBackFun: null
        };
        var opt = $.extend(defaults, options);

        $.ajax({
            url: opt.url,
            data: opt.data,
            type: "POST",
            dataType: "JSON",
            success: function (data) {
                $("#" + opt.formid).bindView({
                    jsonData: data.data,
                    handle: function () {

                    }
                });
                if (opt.backFun)
                    opt.backFun(data.data);
                if (opt.callBackFun)
                    opt.callBackFun(data);
            }
        });
    },
    //封装select数据源
    bindselect: function (options) {
        var defaults = {
            objId: null,
            //请求路径url
            method: null,
            val: null,
            text: null,
            selval: null,
            def: "--请选择--",
            data: null,
            //成功后的处理事件
            handle: function () {
            }
        };
        var opt = $.extend(defaults, options);
        $.ajax({
            type: "POST",
            dataType: "JSON",
            url: opt.method,
            data: opt.data,
            success: function (d) {
                var r = d;//$.parseJSON(d);
                if (r.code == 200) {
                    var html = "";
                    if (opt.def != null) {
                        html = "<option value=''>" + opt.def + "</option>";
                    }
                    var data = r.data;
                    for (var i = 0; i < data.length; i++) {
                        eval("val=data[i]." + opt.val);
                        eval("text=data[i]." + opt.text);
                        if (opt.selval == val) {
                            html += "<option value='" + val + "'  selected>" + text + "</option>";
                        } else {
                            html += "<option value='" + val + "'>" + text + "</option>";
                        }
                    }
                    var arr = opt.objId.split(",");
                    for (var i = 0; i < arr.length; i++) {
                        $("#" + arr[i]).html(html);
                    }
                }
            }
        });
    },
    //绑定列表页面
    bindPage: function (options) {
        var defaults = {
            table: ".table",
            form: null,
            url: null,
            data: null,
            pageIndex: $(".laypage_curr").text() || 1,
            pageSize: 12,
            searchFun: null,      //点击搜索按钮事件
            paging: "paging",     //分页容器id
            fldName: null,       //排序字段
            fldType: null,       //排序类型，desc 倒序，asc 顺序
            Template: null,      //模板html
            successFun: null,      //200 成功回调函数
            handle: function () {  //成功后的处理事件
            }
        };
        var opt = $.extend(defaults, options);
        $table = $(opt.table);
        var paging = opt.paging;
        var $searchForm = opt.form === null ? $("form") : $(opt.form); //查询的条件表单id
        var $searchBtn = $searchForm.find(".btnSearch"); //查询的条件表单id
        if (!opt.url) {
            console.log("地址 不为空");
        }
        if ($searchBtn) {
            $searchBtn.text("搜索中..");
            $searchBtn.attr("disabled", "disabled");
        }
        var fromData = $.extend({pageIndex: opt.pageIndex, pageSize: opt.pageSize}, opt.data);
        $searchForm.ajaxSubmit({
            url: opt.url,
            data: fromData,
            type: "post",
            dataType: "json",
            success: function (d) {
                if (d.code == 404) {
                    if (opt.Template != null) {
                        $table.parent().find("tbody").html("<tr><td colspan='" + $table.parent().find("thead tr th").length + "' style='text-align: center;color: #63B6DC;'>暂无数据</td></tr>");
                    } else {
                        $table.find("tbody").html("<tr><td colspan='" + $table.find("thead tr th").length + "' style='text-align: center;'>暂无数据</td></tr>");
                    }
                    laypage({
                        cont: paging, //容器。值支持id名、原生dom对象，jquery对象,
                        pages: 0, //总页数
                        count: 0,
                        skin: 'molv', //皮肤
                        curr: 1,
                        first: 1, //将首页显示为数字1,。若不显示，设置false即可
                        last: false,//d.pageCount, //将尾页显示为总页数。若不显示，设置false即可
                        prev: false, //若不显示，设置false即可
                        next: false, //若不显示，设置false即可
                        skip: true,
                        jump: function (obj, first) { //触发分页后的回调
                            if (!first) { //点击跳页触发函数自身，并传递当前页：obj.curr
                                opt.pageIndex = obj.curr;
                                BindData.bindPage(opt);
                            }
                        }
                    });
                } else if (d.code == 200) {
                    if ($(".chkids").length > 0) {
                        $(".chkids").val("");
                    }
                    if ($(".chkboxall").length > 0) {
                        $(".chkboxall").prop("checked", false);
                    }
                    if (opt.Template != null) {
                        $table.bindTemplate({
                            jsonData: d,
                            handle: opt.handle,
                            page: opt.pageIndex,
                            pageSize: opt.pageSize,
                            Template: opt.Template
                        });

                    } else {
                        $table.bindTable({
                            jsonData: d,
                            table: $table,
                            handle: opt.handle,
                            page: opt.pageIndex,
                            pageSize: opt.pageSize
                        });
                    }
                    laypage({
                        cont: paging, //容器。值支持id名、原生dom对象，jquery对象,
                        pages: d.data.totalPage, //总页
                        count: d.data.totalRow,  //总行
                        skin: '#222D32', //皮肤
                        curr: d.data.pageIndex,  //当前页
                        first: 1,      //将首页显示为数字1,。若不显示，设置false即可
                        last: false,  //d.pageCount, //将尾页显示为总页数。若不显示，设置false即可
                        prev: '上一页', //若不显示，设置false即可
                        next: '下一页', //若不显示，设置false即可
                        skip: true,
                        jump: function (obj, first) { //触发分页后的回调
                            if (!first) { //点击跳页触发函数自身，并传递当前页：obj.curr
                                opt.pageIndex = obj.curr;
                                BindData.bindPage(opt);
                            }
                        }
                    });
                    if (opt.callbackFunc) {
                        opt.callbackFunc(d);
                    }
                }
                if (opt.handle) {
                    opt.handle(d);
                }
            },
            error: function () {
                //layer.alert("您当前网络不太好，请稍后再试！");
                //layer_msg.close(index);
                //layer_msg.closeAll('loading');
            },
            complete: function () {
                setTimeout(function () {
                    $searchBtn.removeAttr("disabled");
                    $searchBtn.html("搜索");
                }, 500);
            }
        });
        //激活搜索
        $searchBtn.unbind("click");
        $searchBtn.bind("click", function () {
            opt.pageIndex = 1;
            if (opt.searchFun) {
                opt.searchFun(opt);
            } else {
                BindData.bindPage(opt);
            }
        });


        //激活排序
        $table.find("[data-sort]").unbind("click");
        $table.find("[data-sort]").click(function () {
            opt.fldName = $(this).attr("name");
            var sortType = $(this).attr("data-sort");
            opt.fldType = sortType == "" || sortType == "desc" ? "desc" : "asc";
            $table.find(".sortIcon").remove();
            $(this).attr("data-sort", (opt.fldType == "desc" ? "asc" : "desc"));
            if ($(this).find(".sortIcon").length <= 0) {
                $(this).append("<i class='sortIcon icon-arrow-" + (opt.fldType == "desc" ? "down" : "up") + "'></i>");
                $(this).find(".sortIcon").css("cursor", "pointer");
            }
            var sortIcon = $(this).find(".sortIcon");
            $(sortIcon).removeClass("icon-arrow-up").removeClass("icon-arrow-down").addClass("icon-arrow-" + (opt.fldType == "desc" ? "down" : "up"));
            BindData.bindPage(opt);
        });

        //全选
        $table.delegate(".chkboxall", "click", function (e) {
            var chkids = $table.find(".chkids");
            if (chkids.length <= 0) {
                $(this).parent().append("<input type='hidden' class='chkids' value='' />");
            }
            $table.find(".chkbox").prop('checked', $(this).prop('checked'));
            var ids = [];
            $.each($table.find(".chkbox:checked"), function (i, item) {
                ids.push($(item).val());
            });
            $table.find(".chkids").val(ids.join(","));
        });
        //单选
        $table.delegate(".chkbox", "click", function (e) {
            var chkids = $table.find(".chkids");
            if (chkids.length <= 0) {
                $table.find(".chkboxall").parent().append("<input type='hidden' class='chkids' value='' />");
            }
            var ids = [];
            $.each($table.find(".chkbox:checked"), function (i, item) {
                ids.push($(item).val());
            });
            $table.find(".chkids").val(ids.join(","));
        });


        //单选
        $table.delegate(".chkradio", "click", function (e) {
            var chkids = $table.find(".chkids");
            if (chkids.length <= 0) {
                $table.find(".chkradioall").append("<input type='hidden' class='chkids' value='' />");
            }
            var ids = [];
            $.each($table.find(".chkradio:checked"), function (i, item) {
                ids.push($(item).val());
            });
            $table.find(".chkids").val(ids.join(","));
        });
    },
    //绑定checkbox数据源
    bindcheckbox: function (options) {
        var defaults = {
            objId: null,
            url: null,
            val: null,
            text: null,
            checkVal: null,
            textName: null,
            name: null,
            data: null,
            showType: 1,
            callbackFun: function () {
            }
        };
        var opt = $.extend(defaults, options);
        $.ajax({
            type: "POST",
            dataType: "JSON",
            url: opt.url,
            data: opt.data,
            success: function (d) {
                var r = d;//$.parseJSON(d);
                if (r.code == 200) {
                    var html = "";
                    var data = r.data;
                    for (var i = 0; i < data.length; i++) {
                        eval("val=data[i]." + opt.val);
                        eval("text=data[i]." + opt.text);
                        html += '<label class="' + (opt.showType == 1 ? "am-checkbox-inline" : "am-checkbox") + '">';
                        if (opt.textName != null) {
                            html += '<input type="hidden" name="' + opt.textName + '" ' +
                                ((',' + opt.checkVal + ',').indexOf(',' + val + ',') > -1 ? 'value="' + text + '"' : '') + '/>';
                        }
                        html += '  <input type="checkbox"  name="' + opt.name + '" value="' + val + '"' +
                            'data-text="' + text + '" data-am-ucheck ' +
                            ((',' + opt.checkVal + ',').indexOf(',' + val + ',') > -1 ? 'checked' : '') + ' ' +
                            'data-json=\'' + JSON.stringify(data[i]) + '\' data-am-ucheck >' + text;
                        html += ' </label>';
                    }
                    $("#" + opt.objId).append(html);
                    $('[name=' + opt.name + ']').uCheck('enable');
                    if (opt.textName != null) {
                        $("#" + opt.objId).find('input[name=' + opt.name + ']').change(function () {
                            if ($(this).attr("checked") == "checked") {
                                $(this).prev("input[type=hidden]").val($(this).attr("data-text"));
                            } else {
                                $(this).prev("input[type=hidden]").val('');
                            }
                        });
                    }
                    if (opt.callbackFun) {
                        opt.callbackFun(data);
                    }
                }
            }
        });
    },
    //展示页面
    bindHtml: function (options) {
        var defaults = {
            container: null,
            placeholder: true,
            data: null,
            url: null,
            //保存成功回调函数
            callbackFunc: null,
            async: true
        };
        var opt = $.extend(defaults, options);
        if (opt.container == null) alert("请写容器");
        var $container = $(opt.container);
        $.ajax({
            url: opt.url,
            data: opt.data,
            type: "POST",
            dataType: "JSON",
            async: opt.async,
            success: function (d) {
                if (d.code == 404) return;
                var data = d.data;
                $.each($container.find("[data-name]"), function (i, item) {
                    var data_name_value = $(this).attr("data-name");
                    if ($(this).attr("data-name") == '' || undefined) {
                        return
                    }
                    eval("val=data." + data_name_value);
                    var dataType = $(this).attr("data-type");
                    var dataHander = $(this).attr("data-hander");
                    var tag = this.tagName.toLocaleLowerCase();
                    if (dataHander != "" && dataHander != null && dataHander != undefined) {
                        eval("refval=" + dataHander + "(data)");
                        val = refval;
                    }
                    switch (tag) {
                        case "img":
                            if (val == "" || val == null || val == 'null' || val == null) {
                                val = "/static/image/default.png"
                            }
                            $(item).attr("src", val);
                            break;
                        default:
                            if (val == '' || val == null || val == 'null') {
                                // $(item).html("");
                                break;
                            }
                            if (dataType == "sex") {
                                val = "<i class='fa fa-mars text-" + (val == "女" ? "woman" : "man") + "'></i> " + val;
                            } else if (dataType == "date-y-m-d") {
                                val = Comm.formatDate(val);
                            } else if (dataType == "datetime") {
                                val = Comm.formatDateTime(val);
                            } else if (dataType == "date-m") {
                                val = Comm.formatDateTime_(val);
                            } else if (dataType == "date-y") {
                                val = Comm.formatDateYear(val);
                            } else if (dataType == "date") {
                                val = Comm.formatDate(val);
                            } else if (dataType == "datetime_") {
                                val = Comm.formatDateTime(val);
                            } else if (dataType == "int") {
                                val = Comm.int(val);
                            } else if (dataType == "yuan-wan") {
                                val = Comm.yuan_wan(val);
                            } else if (dataType == "wan-yuan") {
                                val = Comm.wan_yuan(val);
                            } else if (dataType == "month-year") {
                                val = Comm.month_year(val);
                            }
                            $(item).html(val);
                            break;
                    }
                });
                $(opt.container).bindView({
                    jsonData: data,
                    handle: function () {
                        handView();
                    }
                });
                if (opt.callbackFunc) {
                    opt.callbackFunc(data, d);
                }
            }
        });
    },
    //删除
    delete: function (options) {
        var defaults = {
            item: null,
            url: null,
            endMethod: null
        };
        var opt = $.extend(defaults, options);
        $("html").on("click", opt.item, function () {
            var id = $(this).attr("data-id");
            layer.confirm('确定删除？', {
                title: '提示',
                btn: ['取消', '确定']
            }, function (index) {
                layer.close(index);
            }, function () {
                $.ajax({
                    url: opt.url,
                    data: {id: id},
                    success: function (d) {
                        if (d.code == 200) {
                            layer.msg(d.msg, {icon: 6, time: 2000});
                            try {
                                eval(opt.endMethod + "()");
                            } catch (e) {
                                console.log(e);
                            }
                        }
                    }
                })

            });
        });
    }
};

//接口处理表格的数据颜色
function handView() {
}

//格式化js时间时间搓，格式yyyy-MM-dd HH:mm:ss
function fullZero(minute) {
    return minute < 10 ? "0" + minute : minute;
}

function formatDateTime(time) {
    if (time == "" || time == null || time == "null" || time == ".." || time == undefined) return "";
    var now = new Date(parseInt(time));
    var year = now.getFullYear();
    var month = now.getMonth() + 1;
    var date = now.getDate();
    var hour = now.getHours();
    var minute = now.getMinutes();
    var second = now.getSeconds();
    return fullZero(year) + "-" + fullZero(month) + "-" + fullZero(date) + " " + fullZero(hour) + ":" + fullZero(minute) + ":" + fullZero(second);
}

function formatDateTime_(time) {
    if (time == "" || time == null || time == "null" || time == ".." || time == undefined) return "";
    var now = new Date(parseInt(time));
    var year = now.getFullYear().toString().substring(2);
    var month = now.getMonth() + 1;
    var date = now.getDate();
    var hour = now.getHours();
    var minute = now.getMinutes();
    return year + "-" + fullZero(month) + "-" + fullZero(date) + " " + fullZero(hour) + ":" + fullZero(minute);
}

function dataHourMin(time) {
    if (time == "" || time == null || time == "null" || time == ".." || time == undefined) return "";
    var now = new Date(parseInt(time));
    var hour = now.getHours();
    var minute = now.getMinutes();
    return fullZero(hour) + ":" + fullZero(minute);
}

//格式化js时间时间搓，格式yyyy-MM-dd
function formatDate(time) {
    if (time == "" || time == null || time == "null" || time == ".." || time == undefined) return "";
    var now = new Date(parseInt(time));
    var year = now.getFullYear();
    var month = now.getMonth() + 1;
    var date = now.getDate();
    return fullZero(year) + "-" + fullZero(month) + "-" + date;
}

//格式化js时间时间搓，格式yyyy-MM
function formatDateMonth(time) {
    if (time == "" || time == null || time == "null" || time == ".." || time == undefined) return "";
    var now = new Date(parseInt(time));
    var year = now.getFullYear();
    var month = now.getMonth() + 1;
    return fullZero(year) + "-" + fullZero(month);
}

//格式化字符串 超过长度用...显示
function formatStr(str, length) {
    if (str == undefined || str == '') {
        return "";
    }
    if (length == undefined || length == '') {
        return str;
    }
    if (str.length <= length) {
        return str;
    } else {
        return str.substring(0, length - 1) + '...';
    }
};